package enterprise.manage.service.impl;

import enterprise.manage.dao.LoginLogDao;
import enterprise.manage.entity.LoginLog;
import enterprise.manage.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by IntelliJ IDEA.
 * User: zhenmingyue
 * Date: 2011-7-8 11:38:22
 * Desc:
 * For :
 */
@Service("loginService")
@Transactional
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginLogDao loginLogDao;

    /**
     * 查询用户登陆失败次数
     * @param userName
     * @return
     */
    public Long getLoginFailedCount(String userName){
        return loginLogDao.getloginFailedCount(userName);
    }

    /**
     * 插入登陆日志
     * @param ip
     * @param logResult
     * @param userName
     * @param userId
     */
    @Override
    public void setLoginLog(String ip, Integer logResult, String userName, Long userId) {
        LoginLog log = new LoginLog();
        log.setIp(ip);
        log.setLogResult(logResult);
        log.setUserId(userId);
        log.setUserName(userName);
        loginLogDao.save(log);
    }
}
